﻿@{
    ViewBag.Title = "支付";
    Layout = "~/Areas/Mall/Views/Shared/MallLayout1.cshtml";
}
<script>
    $(".dh_tool").hide();
    var orderno = "@ViewData["orderno"]";
    var status="@ViewData["status"]";
    $(function() {
        callpay();
    });
    //发起微信支付
    function callpay()
    {
        if (typeof WeixinJSBridge == "undefined")
        {
            if (document.addEventListener)
            {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }
            else if (document.attachEvent)
            {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }
        else{
            jsApiCall();
        }
    }

    //调用微信JS API 支付
    function jsApiCall()
    {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',
            @Html.Raw(ViewData["parameter"]),
            function (res)
            {
                WeixinJSBridge.log(res.err_msg);
                var msg = res.err_msg.split(':')[1];
                if (msg == "ok") {
                    alert("支付成功！");
                    if (orderno.substring(0, 2) == "dc") {
                        location.href = "/mall/food/foodorder?status=" + (parseFloat(status)+1);
                    } else if (orderno.substring(0, 2) == "sm"){ 
                        location.href = "/mall/sm/PaySuccessfull?orderno="+orderno;
                    }else
                    {
                        location.href = "/mall/order/OrderList?sid=1";
                    }
                    return false;
                }else if (msg == "fail") {
                    alert("支付失败！");
                }else if (msg == "cancel") {
                    alert("您已取消支付！");
                }

                if (orderno.substring(0, 2) == "dc") {
                    location.href = "/mall/food/foodorder?status=" + status;
                } else if (orderno.substring(0, 2) == "sm"){ 
                    location.href = "/mall/sm/index";
                }else
                {
                    location.href = "/mall/order/OrderList?sid=1";
                }
                  
            }
        );
    }

</script>